package com.examples.startanactivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Create an explicit Intent
		final Intent activityIntent = new Intent(this, SecondActivity.class);
		activityIntent.putExtra("SomeExtraData", "This is data coming from the first activity");

		// Assign OnClickListener to Activity Button
        Button activityButton = (Button) findViewById(R.id.activityButton);
        activityButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				startActivityForResult(activityIntent, 100);
			}
		});
    }
    
    @Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data){
    	if (requestCode == 100 && resultCode == RESULT_OK) {
    		TextView textView = (TextView) findViewById(R.id.textView);
    		textView.setText(data.getStringExtra("SomeExtraValue"));
        }

    }
}